package com.geostar.constructionland.analyse.factory;

import com.geostar.constructionland.analyse.entity.Block;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author makoto_zhu
 * @Date 2020-12-24 04:44:01
 * @Description
 **/
@Component
public abstract class BlockTypeFactory {
    @Autowired
    private ApplicationContext applicationContext;

    protected abstract List<?> build(List<Block> blocks);

    public List<?> getBlockList(String blockType, List<Block> blocks) {
        if (StringUtils.isEmpty(blockType)) {
            blockType = "GeoJson";
        }
        BlockTypeFactory blockTypeFactory;
        if ("WKT".equals(blockType)) {
            blockTypeFactory = applicationContext.getBean(WKTBlockTypeFactory.class);
        } else {
            blockTypeFactory = applicationContext.getBean(GeoJsonBlockTypeFactory.class);
        }

        return blockTypeFactory.build(blocks);
    }
}
